home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c
- Subject: Re: Trouble with file return code.
- Date: Thu, 11 Jan 1996 12:42:15 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d30vn$k8r@tahko.lpr.carel.fi>
- References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- <xenon@the-fix.sos.on.ca> wrote:
-
- > Im having some trouble getting fread to return NULL when it can't
- >find a specific file...
-
- > else if((ptr=fread(filename1,"rb"))!=NULL)
- > {
- > //do this }
- > else {
- > // do that
- > // this never executes, even if NULL is returned.
- >No matter the file, Null is never returned. Although, when the variable
- >ptr is outputed, the value shown is "0".
- >thankx
- >xenon@the-fix.sos.on.ca
-
- You've got things a little confused here. fread is used to READ the
- contents of an opened file. fopen is the one you use to open the file
- first, fclose to close it. For example:
-
- ...
- FILE *fp;
-
- fp = fopen(filename, "rb");
- if (!fp)
- perror(filename); /* File open failed */
- while (fread(buffer, sizeof(buffer), 1, fp) == 1)
- ProcessBuffer(buffer);
- if (feof(fp))
- ; /* Just reached end of file */
- else if (ferror(fp))
- perror(filename); /* Some read error occurred */
- fclose(fp);
-
- Just keep on looking through your manuals...
-
- Later,
- AriL
- All my opinions are mine and mine alone.
-
-